package com.edu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.io.PrintWriter;
import java.io.StringWriter;
@Controller
public class ExcptionController {
    @RequestMapping("/excption")
    public Object getExcption(){
        System.out.println(5/0);
        return "index.jsp";
    }

    @ExceptionHandler(Exception.class)
    public ModelAndView handlerExcption(Exception e){
        ModelAndView mv = new ModelAndView();
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        System.out.println(sw.toString());
        mv.addObject("msg",pw.toString());
        mv.setViewName("error.jsp");
        return mv;
    }
}
